import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:native_dart_package/loading/loading_util.dart';
import 'package:yt_devops/components/log_utils.dart';
import 'package:yt_devops/configs.dart';
import 'package:yt_devops/pages/devices/device_list/device_list_model.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/routers/router_path.dart';
import 'package:yt_devops/services/device/device_sevices.dart';

class ScanFailMannualAccessController extends GetxController {

  late int siteId;
  final TextEditingController snTextController = TextEditingController();
  @override
  void onInit() {
    super.onInit();
    if (Get.arguments != null) {
      siteId = Get.arguments['siteId'];
    }
  }

  DeviceServices services = Get.find();

  @override
  void onReady() {}

  @override
  void onClose() {}

  ///通过sn码去查询设备是否绑定
  gotoNext() async {
    var param = {'sn': snTextController.text??''};
    showLoading(toast:ResKey.loading.tr);
    var data = await services.getDeviceBySn(param, onError: (error) {
      dismissLoading();
      showError(error.message);
      return false;
    });
    dismissLoading();
    if (data != null) {
      var device = DeviceListModel.fromJson(data);
      Get.toNamed(RouterPath.accessDeviceByScanner,
          arguments: {'device': device, 'siteId': siteId});
    }
  }
}
